import {onMounted, ref, watch} from "vue";
import http from "@/commons/utils/httpUtil";
import {useRoute} from "vue-router";

export default function useQueryGoodsWorldMapData() {
    // 南山港后台数据集合
    const dbData = ref([]);
    const type = useRoute().params.type;

    // 查询南山港区货物吞吐量数据
    const queryGoodsWorldMapPortRankingData = () => {
        if (type === 'out') {
            http.get('/large/queryFreGoodsInPortRanking/2020/20').then((res) => {
                let isValid = res && res.data && res.data && res.data.records.length >= 0;
                dbData.value = isValid ? res.data.records : [];
            });
        } else {
            http.get('/large/queryFreGoodsOutPortRanking/2020/20').then((res) => {
                let isValid = res && res.data && res.data && res.data.records.length >= 0;
                dbData.value = isValid ? res.data.records : [];
            });
        }
    }

    onMounted(() => {
        queryGoodsWorldMapPortRankingData()
    })

    return {
        queryGoodsWorldMapPortRankingData,
        dbData,
    }
}